<?php

class Database 
{
	private $host;
	private $name;
	private $user;
	private $pass;
	private $link;

	public $usersTable = "users";
	public $projectsTable = "projects";
	public $rolesTable = "roles";
	public $userRolesTable = "userroles";
	public $sprintsTable = "sprints";
	public $storiesTable = "stories";
	public $tasksTabel = "tasks";

	function __construct($host = "localhost", $name = "scrummer", $user = "root", $pass = "") {
		$this->host = $host;
		$this->name = $name;
		$this->user = $user;
		$this->pass = $pass;
	}

	function connect() {
		$this->link = mysql_connect($this->host, $this->user, $this->pass) or die("Could not connect to database!");
		mysql_select_db($this->name) or die("Could not open database!");
	}

	function disconnect() {
		if(isset($this->link)) {
			mysql_close($this->link);
		} else {
			mysql_close();
		}
	}

	function execute($query) {
		if(!isset($this->link)) {
			$this->connect();
		}
		mysql_query($query, $this->link) or die("MySql Error: " . mysql_error);
	}

	function query($query) {
		if(!isset($this->link)) {
			$this->connect();
		}
		$result = mysql_query($query, $this->link);

		$returnArray = array();
		while($row = mysql_fetch_array($result)) {
			$returnArray[sizeof($returnArray)] = $row;
		}
		mysql_free_result($result);
		return $returnArray;
	}
}

?>